// See https://sequelize.org/master/manual/model-basics.html
// for more of what you can do here.
const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const users = sequelizeClient.define('users', {
    uname: {
      type: DataTypes.STRING, // 类型是字符串
      allowNull: false, // 不能为空
      unique: true // 是否唯一
    },

    password: {
      type: DataTypes.STRING,
      allowNull: false
    },
    phone: DataTypes.STRING, // 字段名：字段类型
    balance: {
      type: DataTypes.DECIMAL(10,2),
      default: 0,  // 可以设置一个默认值
    },
    sex: DataTypes.INTEGER, // 整数类型
  }, {
    hooks: {
      beforeCount(options) {
        options.raw = true;
      }
    }
  });
  // eslint-disable-next-line no-unused-vars
  users.associate = function (models) {
    // Define associations here
    // See https://sequelize.org/master/manual/assocs.html
  };

  return users;
};
